import { _decorator, CCFloat, Component, Node } from 'cc';
import { PoolObject } from './PoolObject';
import { ResourceManager } from '../Manager/ResourceManager';
const { ccclass, property } = _decorator;

@ccclass('AutoDespawnPoolObject')
export class AutoDespawnPoolObject extends PoolObject {
    
    @property(CCFloat)
    public despawnTime : number;
    private despawnTimer;


    public override onSpawn(): void {
        this.despawnTimer = this.despawnTime;
    }
    
    update(deltaTime: number) {
        if(this.despawnTimer > 0){
            this.despawnTimer-=deltaTime;
            if(this.despawnTimer<=0)
            {

                ResourceManager.despawn(this,null);
            }
        }
    }
}


